This page last changed on Oct 20, 2006 by cholmes.

To add the ability to alter the serviceLevel in the configuration interface, one must alter the the JSP page where the it will be altered, as well as the ActionForm and Actions which communicate with the GeoServer configuration.

Before you begin you must decide where in the interface you want the control to appear on, as the configuration files that pertain to STRUTS are split up to mirror the pages. The WFS Description page contains fields pertaining to information about the WFS, whereas the Content page contains fields which actually affect the way the WFS operates.

Because we are adding a serviceLevel field which defines the services that the WFS provides, our example will modify the Content page.

Config

We have isolated Configuration Information, from the GeoServer Application Information currently being used. Configuration information is captured by a series of classes in the config package. The Advantage of this approach is that it gives us a chance to recast concepts into terms acceptable to the user interface.

Update WFSConfig so it can properly communicate with the DTO object. This is kept simple by adding the property, including getter and setter, and initializing/saving it where appropriate.

  • You must add the property to the ActionForm. In this case, org.vfny.geoserver.form.wfs.WFSContentForm.
    private int serviceLevel;
  • And then the getters and setters.
    /**
     * Access serviceLevel property.
     * 
     * @return Returns the serviceLevel.
     */
    public int getServiceLevel() {
       return serviceLevel;
    }
    
    /**
     * Set serviceLevel to serviceLevel.
     *
     * @param serviceLevel The serviceLevel to set.
     */
    public void setServiceLevel(int serviceLevel) {
       this.serviceLevel = serviceLevel;
    }
  • In WFSConfigContentForm.reset add a call to retrieve the current service level from GeoServer's configuration.
    WFSConfig config = (WFSConfig) context.getAttribute(WFSConfig.CONFIG_KEY);
           serviceLevel = config.getServiceLevel();
            this.enabled = config.isEnabled();
  • In WFSConfigContentForm.validate(), add code to make sure a valid service level was selected. The argument to the ActionError constructor is a String containing the key to a message located in the ApplicationResources.
    if (serviceLevel != WFSDTO.BASIC && serviceLevel != WFSDTO.TRANSACTION) {
                errors.add("serviceLevel", new ActionError("error.serviceLevel.invalid"));
            }

ActionForm (or FormBean)

Subclasses of ActionForm (called form beans ) communicate the state of an HTML form to the Struts framework.

For our purposes we need to pay attention to the following steps:

  • reset - used to set up the FormBean before being sent off to the user
  • populate - used to sync the FormBean with any input from the HTML form
  • validate - used to do a sanity check of the form, and provide the user with quick feedback

For our example we will be changing the WFSContentActionForm.

Here we need to update WFSConfigContentForm to allow the JSP to access and set the serviceLevel property, as well as validate the input before passing it to the Action.

We have a couple of options on how we want to present serviceLevel to the FormBean:

  • As a magic integer - plug and pray approach
  • As a select control based around OGC complient categorizations
  • As a series of check boxes representing the levels of service

We have decided to go with a select control of "Basic", "Transactional", "Complete" since these are documented user level concepts.

Here is our quick checklist:

  • You must add the property to the ActionForm. In this case, org.vfny.geoserver.form.wfs.WFSContentForm.
    private int serviceLevel;

    And then the getters and setters.

    /**
     * Access serviceLevel property.
     * 
     * @return Returns the serviceLevel.
     */
    public int getServiceLevel() {
       return serviceLevel;
    }
    
    /**
     * Set serviceLevel to serviceLevel.
     *
     * @param serviceLevel The serviceLevel to set.
     */
    public void setServiceLevel(int serviceLevel) {
       this.serviceLevel = serviceLevel;
    }
  • In WFSConfigContentForm.reset add a call to retrieve the current service level from GeoServer's configuration.
    WFSConfig config = (WFSConfig) context.getAttribute(WFSConfig.CONFIG_KEY);
            
            serviceLevel = config.getServiceLevel();
            this.enabled = config.isEnabled();
    In WFSConfigContentForm.validate(), add code to make sure a valid service level was selected. The argument to the ActionError constructor is a String containing the key to a message located in the ApplicationResources.
    
            if (serviceLevel != WFSDTO.BASIC && serviceLevel != WFSDTO.TRANSACTION) {
                errors.add("serviceLevel", new ActionError("error.serviceLevel.invalid"));
            }

Action

Actions in struts are used to actually do something. Their execute method is called with a validated FormBean.

For our example we are going to be changing the WFSConfigContentAction.

All that is need to be changed here is a simple call to that saves the selected service level into the configuration.

in WFSConfigContentAction.execute(), add this to save the service level when it is changed in the interface.

WFSConfig config = getWFSConfig();
        config.setEnabled(enabled);
        config.setOnlineResource(new URL(onlineResource));
        config.setServiceLevel(contentForm.getServiceLevel());

Java Server Pages

Here we simply add the control to the appropriate JSP page. Make sure it is within the <html:form> tag that is associated with the ActionForm you changed. In this example, we must make sure to place it within the <html:form action="WFSConfigContentSubmit"> tag. Familiarty with the STRUTS HTML and logic tag libraries really helps here.

Add the following to WFSConfigContent.jsp where ever you want the textbox to appear. It creates a select box with two options in it. One for basic, one for transactional. This is just an example. Feel free to do whatever you want with the control.

<tr>
  <td class="label">
    <span class="help" title="<bean:message key="help.serviceLevel"/>">
      <bean:message key="label.serviceLevel"/>:
    </span>
  </td>
  <td class="datum">
   <html:select property="serviceLevel" size="3">
      <html:option key="label.serviceLevel.basic" value="<%= java.lang.Integer.toString(org.vfny.geoserver.global.dto.WFSDTO.BASIC) %>"/>
      <html:option key="label.serviceLevel.transactional" value="<%= java.lang.Integer.toString(org.vfny.geoserver.global.dto.WFSDTO.TRANSACTIONAL) %>"/>
      <html:option key="label.serviceLevel.complete" value="<%= java.lang.Integer.toString(org.vfny.geoserver.global.dto.WFSDTO.COMPLETE) %>"/>
   </html:select>
</td></tr>

ApplicationResources

Here we must add each of the messages we have created to the ApplicationResource file. This file allows for centralized String messages and for easy internationalization.

in ApplicationResources.properties, add the appropriate keys. Order doesn't matter.

error.serviceLevel.invalid=Invalid service level selected
help.serviceLevel=Defines the level of service that the WFS provides
label.serviceLevel=Service Level
label.serviceLevel.basic=Basic
label.serviceLevel.transactional=Transactional

Using GeoServer Application Information

Now that you have updated the GeoServer application you can make use of your information at runtime. The GeoServer application is stored in the web context, and we have provided several convience methods to allow access.

HttpRequest based access:

HttpRequest httpRequest = (HttpRequest) servletRequest;
Requests.getWFS( httpRequest ).getServiceLevel()

GeoServer Framework (Request/Response/AbstractService)

GeoServer is broken down into various Servlets implemented by decendents of AbstractService. You can use the Request objects to access configuration information when handling a Response.

TransactionResponse example:

protected void execute(TransactionRequest transactionRequest){
  if( (Request.getWFS().getServiceLevel() | WFSDTO.DELETE ) == 0 ){
    throw ServiceException("Transaction Delete not supported");
  }
}

Java Server Pages

Java Server Pages allow direct access to objects stored in the web container.

Java Server Pages Example:

ServiceLevel:<bean:write name="Global.WFS" property="serviceLevel"/>

Struts (Action)

You may also reference GeoServer application information when implementing your own Java Server Pages as part of the GeoServer application.

GeoServerAction example:

Redirect execute( HttpServletRequest request, ){
  if ( (getWFS( request ).getServiceLevel() | WFSDTO.LOCKING ) == 0 ){
     throw ServiceException("Cannot Manage Locks as Locking has been disabled");
  }
  ...
}
Document generated by Confluence on Jan 16, 2008 23:26